package Practice.Practice_02;

import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入数组：");
        String str = sc.nextLine();
        String s = trim(str);
        System.out.println(s);
    }

    public static String trim(String str){
        StringBuilder sb = new StringBuilder(str);

        for(int i = sb.length()-1; i >= 0; i--) {
            if(sb.charAt(i) == ' ') {
                sb.deleteCharAt(i);
            } else {
                break;
            }
        }

        for(int i = 0; i < sb.length(); i++){
            if(sb.charAt(i) == ' ') {
                sb.deleteCharAt(i);
                i--;
            }else {
                break;
            }
        }

        return sb.toString();
    }
}
